<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        var num = parseInt(prompt("请输入一个正整数"));//此时只能输入正整数，并为考虑字符串等的情况；
        var temp = num;
        var count = 0;
        if( num==0 ){
            alert( temp + "是 1 位数" );
        }else{
            while(num != 0) {
            count++;   //统计位数；
            num = parseInt(num/10); //赋值给 num 以备下次循环使用；
            }
            alert(temp+" 是 "+count+" 位数");
        }

    </script>
</body>
</html>
